package com.demo.utils;

import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
import com.demo.utils.mapper.EmpMapper;
import org.apache.commons.io.FilenameUtils;
import org.apache.ibatis.reflection.ArrayUtil;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author ausu
 * @version 1.0
 * @description: TODO
 * @date 2023/1/15 13:14
 */
@SpringBootTest
public class CollectionUtils {

    @Autowired
    private EmpMapper empMapper;

    @Test
    public void arrayToList() {
        Integer[] integers = {1,2,3,4,5,6};
        List list = org.springframework.util.CollectionUtils.arrayToList(integers);
        System.out.println("list:" + list);
        boolean empty = org.springframework.util.CollectionUtils.isEmpty(list);
        System.out.println("isEmpty :" + empty);
    }

    @Test
    public void apacheCollectionTest() {
        // 集合判空
        ArrayList<Object> aList = Lists.newArrayList(1,33,4544,7777);
        ArrayList<Object> bList = Lists.newArrayList(1,12,66);
        // 获取并集
        Collection union = org.apache.commons.collections.CollectionUtils.union(aList, bList);
        System.out.println(union);
        // 获取交集
        Collection intersection = org.apache.commons.collections.CollectionUtils.intersection(aList, bList);
        System.out.println("intersection" + intersection);
        // 获取交集的补集
        Collection disjunction = org.apache.commons.collections.CollectionUtils.disjunction(aList, bList);
        System.out.println("disjunction:" + disjunction);
        // 获取差集
        Collection subtract = org.apache.commons.collections.CollectionUtils.subtract(aList, bList);
        System.out.println("subtract:" + subtract);


//        CollectionUtils.select：根据条件筛选集合元素
//        CollectionUtils.transform：根据指定方法处理集合元素，类似List的map()
//        CollectionUtils.filter：过滤元素，雷瑟List的filter()
//        CollectionUtils.find：基本和select一样
//        CollectionUtils.collect：和transform 差不多一样，但是返回新数组
//        CollectionUtils.forAllDo：调用每个元素的指定方法
//        CollectionUtils.isEqualCollection：判断两个集合是否一致
    }

    @Test
    public void testArrayUtils() {
        ArrayList<Integer> integers = Lists.newArrayList(11, 33);
        Object[] array = integers.toArray();
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
            System.out.println("array.length:" + array.length);
        }
    }


}
